
const db = wx.cloud.database();
const _ = db.command;
//字段自增
const inc = (dbName,id,prop,callback) => {
  var data = {};
  data[prop] = _.inc(1);
  db.collection(dbName).doc(id).update({
    data: data,
    success(res) {
      if (callback)
      {
        callback(res);
      }
    }
  })
}

//更新一个属性
const updateProp = (dbName, id, prop, val, callback) => {
  var data = {};
  data[prop] = val;
  db.collection(dbName).doc(id).update({
    data: data,
    success(res) {
      if (callback) {
        callback(res);
      }
    }
  })
}

module.exports = {
  inc: inc,
  updateProp: updateProp
}